package com.ywh.composetest.widget

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog

@Composable
fun CommonTipDialog(
    showDialogState: MutableState<Boolean>,
    tip: String,
    onOkAction: () -> Unit
) {
    if (showDialogState.value) {
        Dialog(onDismissRequest = {
            showDialogState.value = false
        }) {
            Box(
                modifier = Modifier.background(Color.White, shape = RoundedCornerShape(8.dp)),
                contentAlignment = Alignment.Center
            ) {
                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                    Spacer(modifier = Modifier.height(24.dp))
                    Text(modifier = Modifier.padding(horizontal = 12.dp), text = tip)
                    Spacer(modifier = Modifier.height(24.dp))
                    Box(
                        modifier = Modifier
                            .size(100.dp, 40.dp)
                            .background(
                                Color.Green, shape = RoundedCornerShape(8.dp)
                            )
                            .clickable {
                                showDialogState.value = false
                                onOkAction.invoke()
                            },
                        contentAlignment = Alignment.Center
                    ) {
                        Text(
                            text = "知道了",
                            fontSize = 14.sp,
                            color = Color.White,
                            fontWeight = FontWeight.Bold
                        )
                    }
                    Spacer(modifier = Modifier.height(16.dp))
                }
            }
        }
    }
}